
/**
 * 打开文件上传对话框
 * @param dialog_title 对话框标题
 * @param callback 回调方法，参数有（当前dialog对象，选择的文件数组，你设置的extra_params）
 * @param extra_params 额外参数，object
 * @param multi 是否可以多选
 * @param filetype 文件类型，image,video,audio,file
 * @param app  应用名，CMF的应用名
 */
function open_upload_dialog(dialog_title,callback,extra_params,multi,filetype,app){
	multi = multi?1:0;
	filetype = filetype?filetype:'image';
	app = app?app:GV.APP;
    var params = '&multi='+multi+'&filetype='+filetype+'&app='+app ;
    
    //var content = '<iframe id="upload-iframe" src="' + GV.MODULE+'/Asset/plupload' + '" width="100%" height="99%" frameborder="0" scrolling="no"></iframe>';
    var content = '<iframe id="upload-iframe" src="http://127.0.0.1/PHPMyWind_5.4/admin/plugin/uploadify/index.php?title=%E7%BC%A9%E7%95%A5%E5%9B%BE%E4%B8%8A%E4%BC%A0&type=image&desc=image&num=1&size=2097152&frame=uploadify&input=picurl&area=undefined" width="100%" height="99%" frameborder="0" scrolling="no"></iframe>';
    
    if ( $("#upload_dialog").length > 0 ) { 
    	$("#upload_dialog").dialog({content: content});
	}else{ 
    	$("body").append('<div id="upload_dialog"></div>');
    	$('#upload_dialog').dialog({
		    title: '图片上传',
		    width: 650,
		    height: 420,
		    closed: false,
		    cache: false,
		    //href: GV.MODULE+'/Asset/plupload',
		    content: content,
		    modal: true,
		    buttons:[{
				text:'Save',
				handler:function(){
					if (typeof callback =='function') {
		            	//var iframewindow = $("#upload-iframe").contentWindow;
		            	var files=document.getElementById('upload-iframe').contentWindow.get_selected_files();
		            	if(files){
		            		callback.apply(this, [this, files,extra_params]);
		            		$('#upload_dialog').dialog('close');
		            	}else{
		            		return false;
		            	}
		            	
		            }
				}
			},{
				text:'Close',
				handler:function(){}
			}],
		});
    	
   	}
	
    /* Wind.use("artDialog","iframeTools",function(){
        art.dialog.open(GV.ROOT+'index.php?g=asset&m=asset&a=plupload'  + params, {
	        title: dialog_title,
	        id: new Date().getTime(),
	        width: '650px',
	        height: '420px',
	        lock: true,
	        fixed: true,
	        background:"#CCCCCC",
	        opacity:0,
	        ok: function() {
	            if (typeof callback =='function') {
	            	var iframewindow = this.iframe.contentWindow;
	            	var files=iframewindow.get_selected_files();
	            	if(files){
	            		callback.apply(this, [this, files,extra_params]);
	            	}else{
	            		return false;
	            	}
	            	
	            }
	        },
	        cancel: true
	    });
    });*/
}

/**
 * 单个图片上传
 * @param dialog_title 上传对话框标题
 * @param input_selector 图片容器
 * @param extra_params 额外参数，object
 * @param app  应用名,CMF的应用名
 */
function upload_one_image(dialog_title, input_selector, extra_params, app) {
    open_upload_dialog(dialog_title, function (dialog, files) {
        $(input_selector).val(files[0].filepath);
        $(input_selector + '-preview').attr('src', files[0].preview_url);
        $(input_selector + '-name').val(files[0].name);
    }, extra_params, 0, 'image', app);
}
